package cn.cmcc.intertelecom.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.cmcc.intertelecom.bean.GeneratorRoom;
import cn.cmcc.intertelecom.bean.GeneratorRoomExample;
import cn.cmcc.intertelecom.bean.GeneratorRoomExample.Criteria;
import cn.cmcc.intertelecom.dao.GeneratorRoomMapper;

@Service
public class GeneratorRoomService {
	
	@Autowired
	private GeneratorRoomMapper gRoomMapper;
	

	/**
	 * 根据已知条件查询所有的机房信息，包括其管理员和所属部门
	 * @param gRoom 
	 * @return
	 */
	public List<GeneratorRoom> queryRoomAndDeptWithAdmin(GeneratorRoom gRoom) {
		GeneratorRoomExample example =new GeneratorRoomExample();
		Criteria criteria = example.createCriteria();
		if(gRoom.getGroomName() !=null && !gRoom.getGroomName().equals("")){
			criteria.andGroomNameEqualTo(gRoom.getGroomName());
		}
		if(gRoom.getDeptId() !=null && !gRoom.getDeptId().equals("")){
			criteria.andDeptIdEqualTo(gRoom.getDeptId());
		}
		if(gRoom.getUserId() !=null && !gRoom.getUserId().equals("")){
			criteria.andUserIdEqualTo(gRoom.getUserId());
		}
		if(gRoom.getGroomAddress() !=null && !gRoom.getGroomAddress().equals("")){
			criteria.andGroomAddressEqualTo(gRoom.getGroomAddress());
		}
		
		return gRoomMapper.selectByExampleWithDeptAndAdmin(example);
	}

	/**
	 * 查询所有的机房信息，包括其管理员和所属部门
	 * @return
	 */
	public List<GeneratorRoom> getAllRoomAndDeptWithAdmin() {
		GeneratorRoomExample example=new GeneratorRoomExample();
		example.setOrderByClause("id");

		return gRoomMapper.selectByExampleWithDeptAndAdmin(example);
	}

	/**
	 * 保存机房信息
	 * @param gRoom
	 */
	public void saveGRoom(GeneratorRoom gRoom) {
		gRoomMapper.insertSelective(gRoom);
		
		
	}

	/**
	 * 根据主键查询 一条机房信息 包括部门和用户
	 * @param gRoomId
	 * @return
	 */
	public GeneratorRoom selectByPrimaryKeyWithDeptAndAdmin(Integer gRoomId) {
		
		return gRoomMapper.selectByPrimaryKeyWithDeptAndAdmin(gRoomId);
	}

	/**
	 * 更新机房信息
	 * @param gRoom
	 */
	public void updateGRoom(GeneratorRoom gRoom) {
		gRoomMapper.updateByPrimaryKey(gRoom);
		
	}

	/**
	 * 批量删除机房信息
	 * @param ids
	 */
	public void deleteBatch(List<Integer> ids) {
		GeneratorRoomExample example=new GeneratorRoomExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(ids);
		gRoomMapper.deleteByExample(example);
		
	}
	//删除一条信息
	public void deleteDept(int id) {

		gRoomMapper.deleteByPrimaryKey(id);
	}

	
}
